package cn.kingyang.yiyi.ui.fragment;

import android.support.v7.widget.GridLayoutManager;
import android.view.View;

import com.jtech.listener.OnItemClickListener;
import com.jtech.view.JRecyclerView;
import com.jtech.view.RecyclerHolder;
import com.jtech.view.RefreshLayout;

import java.util.List;

import butterknife.BindView;
import cn.kingyang.yiyi.R;
import cn.kingyang.yiyi.mvp.model.bean.HttpData;
import cn.kingyang.yiyi.mvp.model.bean.NobleVideo;
import cn.kingyang.yiyi.mvp.presenter.ForumPresenter;
import cn.kingyang.yiyi.mvp.view.ForumView;
import cn.kingyang.yiyi.ui.adapter.ForumVideoAdapter;
import cn.kingyang.yiyi.ui.fragment.base.BaseMainFragment;
import cn.kingyang.yiyi.ui.view.MyDecoration;
import cn.kingyang.yiyi.utils.AppUtil;


/**
 * Created by Administrator on 2017/2/28.
 */

public class ForumFragment extends BaseMainFragment<ForumView, ForumPresenter> implements ForumView, OnItemClickListener, RefreshLayout.OnRefreshListener {
    @BindView(R.id.forum_video_jr)
    JRecyclerView mVideoJRV;//
    private ForumVideoAdapter mVideoAdapter;//
    @BindView(R.id.refreshlayout)
    RefreshLayout refreshlayout;//下拉刷新组件
    public static ForumFragment newInstance() {
        return new ForumFragment();
    }

    @Override
    protected ForumPresenter getPresenter() {
        return new ForumPresenter();
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_forum;
    }
    @Override
    protected void initView(View view) {
        mVideoAdapter =new ForumVideoAdapter(_mActivity);
        mVideoJRV.addItemDecoration(new MyDecoration(getActivity(), MyDecoration.HORIZONTAL_LIST));
        mVideoJRV.setLayoutManager(new GridLayoutManager(getActivity(),1));
        mVideoJRV.setAdapter(mVideoAdapter);
        mVideoJRV.setOnItemClickListener(this);
        refreshlayout.setOnRefreshListener(this);
        refreshlayout.startRefreshing();
    }



    @Override
    public void showProgress() {

    }

    @Override
    public void hideProgress() {

    }

    @Override
    public void onError(Throwable t) {

    }
    @Override
    public void doForumInfo(HttpData<List<NobleVideo>> data) {
        mVideoAdapter.setDatas(data.getData());
        refreshlayout.refreshingComplete();
    }

    @Override
    public void onItemClick(RecyclerHolder recyclerHolder, View view, int i) {
        AppUtil.showPopupWindow(_mActivity,getView());
    }

    @Override
    public void onRefresh() {
        mPresenter.getForumInfo();
    }
}
